import { getRolesReq } from '@/service/modules/user'
import { Role } from '@/service/modules/user/types'
import { reactive } from 'vue'

//角色是公共方法
export function useRole() {
  const roleVariables = reactive({
    roleOptions: new Array<{ value: number; label: string }>()
  })
  const getRoleOptions = async (type: 0 | 1) => {
    const res = await getRolesReq(type)
    if (res.resp_code === 0) {
      const roles = res.data as Role[]
      roles.map((item) =>
        roleVariables.roleOptions.push({
          value: item.id,
          label: item.name
        })
      )
    }
  }
  return { roleVariables, getRoleOptions }
}
